export class StdAnnexV2 {
  constructor(node) {
    this.node = node
    this.annexNumberNode = node.querySelector('[data-annex-number]')
    this.annexNumberEnNode = node.querySelector('[data-annex-number] span[data-lang="en"]')

    this.annexTypeNode = node.querySelector('[data-annex-type]')
    this.annexTypeEnNode = node.querySelector('[data-annex-type] span[data-lang="en"]')

    this.annexNameNode = node.querySelector('[data-annex-title]')
    this.annexNameEnNode = node.querySelector('[data-annex-title][data-lang="en"]')

    this.blockList = []
  }
  get data() {
    const annexNumber = {
      dataType: 'annex_number',
      blockId: this.annexNumberNode?.dataset?.blockId,
      textData: {
        dataId: this.annexNumberNode?.dataset?.id,
        contentList: [
          {
            contentType: 'text',
            contentNumber: this.annexNumberNode?.dataset?.annexNumber,
            content: '附录',
            fullContent: '附录' + this.annexNumberNode?.dataset?.annexNumber
          }
        ]
      }
    }
    const annexType = {
      dataType: 'annex_type_name',
      blockId: this.annexTypeNode?.dataset?.blockId,
      textData: {
        dataId: this.annexTypeNode?.dataset?.id,
        contentList: [
          {
            contentType: 'text',
            content: this.annexTypeNode?.dataset?.annexType,
            fullContent:
              '(' + (this.annexTypeNode?.dataset?.annexType === 'normativeAnnex' ? '规范性附录' : '资料性附录') + ')'
          }
        ]
      }
    }

    if (this.annexNumberEnNode) {
      annexNumber.textData.contentList.push({
        contentType: 'text',
        contentNumber: this.annexNumberNode?.dataset?.annexNumber,
        content: 'Annex',
        fullContent: '(' + 'Annex ' + this.annexNumberNode?.dataset?.annexNumber + ')'
      })
    }

    if (this.annexTypeEnNode) {
      annexType.textData.contentList.push({
        contentType: 'text',
        content: this.annexTypeNode?.dataset?.annexType,
        fullContent:
          '(' + (this.annexTypeNode?.dataset?.annexType === 'normativeAnnex' ? 'Normative' : 'Informative') + ')'
      })
    }

    this.blockList.push(annexNumber, annexType)

    this.blockList.push({
      dataType: 'annex_title',
      blockId: this.annexNameNode?.dataset?.blockId,
      textData: {
        dataId: this.annexNameNode?.dataset?.id,
        contentList: [
          {
            contentType: 'text',
            content: this.annexNameNode?.innerText,
            fullContent: this.annexNameNode?.innerText
          }
        ]
      }
    })

    if (this.annexNameEnNode) {
      this.blockList.push({
        dataType: 'annex_title',
        blockId: this.annexNameEnNode?.dataset?.blockId,
        textData: {
          dataId: this.annexNameEnNode?.dataset?.id,
          dataLang: 'en',
          contentList: [
            {
              contentType: 'text',
              content: this.annexNameEnNode?.innerText,
              fullContent: this.annexNameEnNode?.innerText
            }
          ]
        }
      })
    }

    return this.blockList
  }
}
